<!DOCTYPE html>
<html lang="zh-cn">
	<head>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
	    <title></title>
	    <#include "/common/meta.ftl"/>
	    <link rel="stylesheet" href="${_b}/static/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
	    <script type="text/javascript" src="${_b}/static/zTree_v3/js/jquery.ztree.all.js"></script>
		<script>
			var setting = {
				async: {
					enable: true,
					url: "./organTreeForUser"
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					onClick: function(event, treeId, treeNode){
						$("#organID").val(treeNode.id);
						$("#organID_V").val(treeNode.name);
						hideMenu();
					}
				}
			};
			$(function(){
				$("#cbAll").click(function(){
					$(".CK").prop('checked',$("#cbAll").prop('checked'));
				});
				<#if (flag!'')!=''>
				var msg = new top.$.zui.Messager('提示消息：${flag!''}', {
		                	type : 'success',
		                	fade : true,
		                	icon : 'ok-sign',
		                	time : 3000,
		                	scale : true
		    	});
				msg.show();
				</#if>
			});
			function hasChecked(){
				var cbs = $(".CK");
				for(var i=0;i<cbs.length;i++){
					if(cbs[i].checked == true){
						return true;
					}
				}
				return false;
			}
			function plDelete(organID,userName,userLoginName){
				if(!hasChecked()){
					var msg = new top.$.zui.Messager('提示消息：请选择要批量删除的数据！', {
		                	type : 'warning',
		                	fade : true,
		                	icon : 'warning-sign',
		                	time : 3000,
		                	scale : true
			    	});
					msg.show();
				}else{
					if(confirm("您确定要删除这些数据吗？")){
						var cbs = $(".CK");
						var ids = "";
						for(var i=0;i<cbs.length;i++){
							if(cbs[i].checked == true){
								ids += cbs[i].value + ",";
							}
						}
						ids = ids.substring(0,ids.length-1);
						$("#form").attr("action" , "./userDelete?ids="+ids);
						$("#form").submit();
					}
				}
			}
			function add(organid){
				location.href = "./userForm?organID="+organid;
			}
			function showMenu() {
				$.fn.zTree.init($("#organForSelect"), setting);
				var cityObj = $("#organID_V");
				var cityOffset = $("#organID_V").offset();
				$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() - 8 + "px"}).slideDown("fast");
				$("body").bind("mousedown", onBodyDown);
			}
			function hideMenu() {
				$("#menuContent").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDown);
			}
			function onBodyDown(event) {
				if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
					hideMenu();
				}
			}
			function clearSearch(){
				$("#organID").val('');
				$("#organID_V").val('');
				$("#userName").val('');
				$("#userLoginName").val('');
				$("#form").submit();
			}
		</script>
	</head>
	<body style="padding:5px;">
	<div id="menuContent" class="menuContent" style="display:none; position: absolute;z-index:1000000000000;">
		<ul id="organForSelect" class="ztree form-control" style="margin-top:0;margin-top: 10px;overflow-y:scroll;height:290px;background: #f0f6e4;padding-right:20px;width:240px;"></ul>
	</div>
	<form  id="form" action="./userForList" method="post">
		<div style="margin-bottom:4px;">
			<button class="btn btn-primary" onclick="add('${organID?default('')}');" type="button"><i class="icon icon-plus"></i> 添加用户</button>
			<button class="btn btn-danger" onclick="plDelete('${organID?default('')}','${userName!''}','${userLoginName!''}');" type="button"><i class="icon icon-trash"></i> 批量删除</button>
			<div style="float:right;margin-bottom:4px;">
			<div class="input-group" style="width:340px;">
				<span class="input-group-addon">组织机构</span>
				<input type="hidden" id="organID" name="organID" value="${organID!''}" />
	           	<input type='text' id='organID_V' name="organID_V" readonly onclick="showMenu(); return false;" value='${organID_V!''}' class="form-control" style="width:220px;"/>
		   		<span class="input-group-addon" style="border-left:0px;border-right:0px;">姓名</span> 
		   		<input id="userName" name="userName" value="${userName!''}" type="text" class="form-control" style="width:120px;">
			 	<span class="input-group-addon" style="border-left:0px;border-right:0px;">登录名</span> 
			 	<input id="userLoginName" name="userLoginName" value="${userLoginName!''}" type="text" class="form-control" style="width:120px;"> 
			  	<span class="input-group-btn">
			    	<button class="btn btn-primary" type="submit"><i class="icon icon-search"></i> 搜索</button>
			    	<button class="btn" type="button" onclick="clearSearch();"><i class="icon icon-undo"></i> 清空</button>
			  	</span>
			</div>
			</div>
		</div>
		
		<table class="table table-hover table-bordered table-condensed" style="margin:0px;">
		  	<thead>
		    	<tr>
		    		<th style="width:40px;text-align:center;"><input type="checkbox" name="cbAll" id="cbAll" /></th>
		    		<th style="text-align:center;width:60px;">序号</th>
			      	<th style="text-align:center;width:120px;">登录名</th>
			      	<th style="text-align:center;width:120px">姓名</th>
			      	<th style="text-align:center;width:60px">性别</th>
			      	<th style="text-align:center;width:120px">手机号码</th>
			      	<th style="text-align:center;">所属组织</th>
			      	<th style="text-align:center;width:60px;">排序</th>
			      	<th style="text-align:center;width:60px;">状态</th>
		    	</tr>
		  	</thead>
	  		<tbody>
	  			<#list data.records as x>
	  			<tr>
	  				<td style="text-align:center"><input type="checkbox" class="CK" value="${x.userID}"/></td>
	  				<td style="text-align:center">${x_index+1}</td>
			      	<td style="text-align:center"><a href="./userForm?userID=${x.userID}">${x.userLoginName?default('')}</a></td>
			      	<td style="text-align:center"><a href="./userForm?userID=${x.userID}">${x.userName?default('')}</a></td>
			      	<td style="text-align:center;vertical-align:bottom;">
			      		<#if (x.userSex?default(1))==1>
			      			<img src="${_b}/static/zTree_v3/css/ext_icons/user/user.png" />
			      		<#else>
			      			<img src="${_b}/static/zTree_v3/css/ext_icons/user/user_female.png"/>
			      		</#if>
			      	</td>
			      	<td style="text-align:center">${x.userMobile?default('')}</td>
			      	<td style="text-align:left">${x.organName?default('')}</td>
			      	<td style="text-align:center">${x.userOrder?default('')}</td>
			      	<td style="text-align:center">
				      	<#if x.userStatus?exists&&x.userStatus==1>
				      	<span style=color:green><b>正常</b></span>
				      	<#elseif x.userStatus?exists&&x.userStatus==11>
				      	<span style=color:orange><b>未激活</b></span>
				      	<#else>
				      	<span style=color:red><b>已停用</b></span>
				      	</#if>
			      	</td>
			    </tr>
			    </#list>
	  		</tbody>
		</table>
		<#include "/common/page_v1.ftl"/>
		</form>
	</body>
</html>